﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;
using System.Data;

namespace Runda.CMS.Portal.Finiance
{
    public partial class SalerMonthCheckOffsView : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["UserID"] != null && Request.QueryString["UserID"].ToString() != "")
                {
                    txtUserID.Value = Request.QueryString["UserID"];
                    BindList(1);
                }
            }
        }
        private void BindList(int pageindex)
        {

            int RecordCount = 0;
            List<ArmCheckOffsForMonthEntity> list = new ArmCheckOffsForMonthBll().GetAll<ArmCheckOffsForMonthEntity> (" and Month =" + Request.QueryString["Month"] + " and Year = " + Request.QueryString["Year"] + " and UserID='" + txtUserID.Value + "'"," convert(int,year+month) desc", AspNetPager1.PageSize, pageindex, out RecordCount);

            RepeaterUsers.DataSource = list;
            RepeaterUsers.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void RepeaterUsers_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                BindList(1);
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindList(AspNetPager1.CurrentPageIndex);
        }

        protected void RepeaterUsers_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label txtFunds = e.Item.FindControl("txtFunds") as Label;
            Label txtYear = e.Item.FindControl("txtYear") as Label;
            Label txtMonth = e.Item.FindControl("txtMonth") as Label;
            Label txtCheckOffsTypeValue = e.Item.FindControl("txtCheckOffsTypeValue") as Label;
            Label txtCheckOffsType = e.Item.FindControl("txtCheckOffsType") as Label;
            Label lblComment = e.Item.FindControl("lblcomment") as Label;

            if (txtFunds != null && txtYear != null && txtMonth != null)
            {
                List<ArmUserPerformanceEntity> list = new ArmUserPerformanceBll().GetAll<ArmUserPerformanceEntity>(" and Month=" + txtMonth.Text + " and Year=" + txtYear.Text + " and UserID='" + Request.QueryString["UserID"] + "'");
                decimal totalFund = 0;
                foreach (ArmUserPerformanceEntity entity in list)
                {
                    totalFund = totalFund + entity.Reward + entity.Fine;
                }
                txtFunds.Text = totalFund.ToString();

                txtCheckOffsType.Text = new SysDictionaryBll().Get<SysDictionaryEntity>(new Guid(txtCheckOffsTypeValue.Text)).Code;
            }


        } 
    }
}
